<template>
  <div class="content-nav">
    <div class="center-content" v-loading="tabLoading">
      <div class="nav">
        <div class="tab-item">
          <router-link to="/" exact>
            首页
          </router-link>
        </div>
        <router-link :to=" {path:'/spotlight/spotlightList',query:{id:tabActive}}" class="tab-item" v-for="(item,index) in tabList" :key="item.id" >
          <div :class="tabActive===item.id?'active':''" @click="tabActive=item.id" class="tab-item">{{ item.name }}</div>
        </router-link>
      </div>
<!--      <div class="search">-->
<!--        <input type="text" placeholder="请输入关键词" v-model="title">-->
<!--        <router-link :to="{path:'/searchList',query:{title:title}}">-->
<!--          <img src="@/assets/home/search.png" alt="">-->
<!--        </router-link>-->
<!--      </div>-->
    </div>
  </div>
</template>

<script>
import {getCategoryApi} from "@/api/spotlight";
import {createParams} from "@/utils/utils";

export default {
  name: "Nav",
  data() {
    return {
      activeIndex2: '1',
      tabLoading:false,
      tabActive: 1,
      name: '新闻分类',
      title: '',
      tabList:[{
        id: 1,
        name: '首页'
      },]
    };
  },
  watch:{//监听
    tabActive:{
      handler(value){
        this.fairActive = value
        sessionStorage.setItem('currentPage',this.fairActive)
      }
    },
  },
  methods: {
    getCategory() {
      this.tabLoading = true
      getCategoryApi({name:this.name,is_main:1}).then((res) => {
        this.tabList = res.result;
      }).finally(()=>{
        this.tabLoading = false
      })
    },
  },

  mounted() {
    this.getCategory()
  }
}
</script>

<style scoped lang="scss">
.content-nav{
  width: 100%;
  height: 50px;
  background: linear-gradient(to right, #FF5C61 30%, #FF5C61 60%, #FF5B5C 90%);
.center-content{
  width: 1220px;
  height: 50px;
  margin: 0 auto;
  display: flex;
  .nav{
    width: 100%;
    height: 100%;
    justify-content: space-between;
    display:flex;
    .tab-item{
      width: 98px;
      height: 50px;
      text-align: center;
      line-height: 50px;
      color: #FFF;
      cursor: pointer;
    }
    .tab-item.active{
      color: #FBBDBF;
    }
    a{
      text-decoration: none;
      color: #FFF;
    }
    .router-link-active {
      text-decoration: none;
      color: #FBBDBF;
    }
  }
  .search{
    position: relative;
    input{
      box-sizing: border-box;
      height: 40px;
      background-color: hsla(222, 108, 210, 0.3);
      margin-top: 5px;
      font-size: 15px;
      //margin-right: 30px;
      padding-right: 35px;
    }
    img{
      position: absolute;
      width: 30px;
      height: 30px;
      right: 3px;
      top: 10px;
    }
  }
}
}
</style>
